{include file="./public/footer" /}
{include file="./public/menu" /}
<!--引入kindeditor编辑器-->
<script src="__STATIC__/Admin/kindeditor/kindeditor-all.js"></script>
<!--/sidebar-->
<div class="main-wrap">

    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="/admin.php">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/admin.php/ware/lists">商品管理</a><span class="crumb-step">&gt;</span><span>编辑商品</span></div>
    </div>
    <div class="result-wrap">
        <div class="result-content">
            <form  id="andy_form"  name="myform" enctype="multipart/form-data">
                <table class="insert-tab" width="100%">
                    <tbody><tr>
                        <th width="120"><i class="require-red">*</i>商品分类：</th>
                        <td>
                            <select name="ware_type_id" id="type_id" class="required" onchange="getWareType(this)">
                                <option value="">请选择</option>
                                {volist name="wareType" id="wt"}
                                    <option value="{$wt.type_id}" {if ($ware.ware_type_id eq $wt.type_id)}selected{/if}>{$wt.type_name}</option>
                                {/volist}
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th width="120"><i class="require-red">*</i>分类：</th>
                        <td>
                            <select name="class_id" id="class_id" class="required">
                                <option value="">请选择</option>
                                <option value="1"  {if ($ware.class_id eq 1)}selected{/if}>长滩玩乐</option>
                                <option value="2"  {if ($ware.class_id eq 2)}selected{/if}>薄荷玩乐</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require-red">*</i>商品名称：</th>
                        <td>
                            <input class="common-text required"  name="title" size="50"  type="text" value="{$ware.title}">
                        </td>
                    </tr>
                    <tr>
                        <th>商品描述：</th>
                        <td>
                            <input class="common-text required"  name="remarks" size="50"  type="text" value="{$ware.remarks}">
                        </td>
                    </tr>
                    <tr>
                        <th>商品属性</th>
                        <td>
                            {volist name="config" id="c"}
                                <input type="checkbox" onclick="check(this)" name="config" value="{$c.id}" {if (in_array($c.id,$ware.config))}checked{/if}>&nbsp;{$c.title}&nbsp;
                            {/volist}
                        </td>
                    </tr>
                    <tr >
                        <th><i class="require-red">*</i>商品价格：</th>
                        <td>
                            <input class="common-text" name="price" size="50"  type="text" value="{$ware.price}">
                        </td>
                    </tr>
                    <tr id="wareCollagePrice" style="display: none;">
                        <th><i class="require-red">*</i>商品团购价：</th>
                        <td>
                            <input class="common-text" name="collage_price" size="50"  type="text" value="{$ware.collage_price}">
                        </td>
                    </tr>
                    <tr id="wareCollagePeople" style="display: none;">
                        <th><i class="require-red">*</i>团购人数：</th>
                        <td>
                            <input class="common-text" name="collage_people" size="50"  type="text" value="{$ware.collage_people}">
                        </td>
                    </tr>
                    <tr id="wareCollageTime" style="display: none;">
                        <th><i class="require-red">*</i>团购时间：</th>
                        <td>
                            <input class="common-text" name="collage_time" size="50"  type="text" value="{$ware.collage_time}">
                        </td>
                    </tr>
                    <tr id="wareSeckillPrice" style="display: none;">
                        <th><i class="require-red">*</i>商品秒杀价：</th>
                        <td>
                            <input class="common-text" name="seckill_price" size="50"  type="text" value="{$ware.seckill_price}">
                        </td>
                    </tr>
                    <tr id="startTime" style="display: none;">
                        <th><i class="require-red">*</i>开始时间：</th>
                        <td>
                            <input class="common-text" name="seckill_start_time" size="50"  type="text" value="{$ware.seckill_start_time}">
                        </td>
                    </tr>
                    <tr id="endTime" style="display: none;">
                        <th><i class="require-red">*</i>结束时间：</th>
                        <td>
                            <input class="common-text" name="seckill_end_time" size="50"  type="text" value="{$ware.seckill_end_time}">
                        </td>
                    </tr>
                    <tr id="seckillNum" style="display: none;">
                        <th><i class="require-red">*</i>秒杀总数量：</th>
                        <td>
                            <input class="common-text" name="seckill_num" size="50"  type="text" value="{$ware.seckill_num}">
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require-red">*</i>出发城市：</th>
                        <td>
                            <input class="common-text required"  name="city" size="50"  type="text" value="{$ware.city}">
                        </td>
                    </tr>
                    <tr>
                        <th>封面图</th>
                        <td>
                            <input id="file_upload"  type="file" multiple="true" >
                            <img style="display: none" id="upload_org_code_img" src="{$ware.cover}" width="150" height="150">
                            <input id="file_upload_image" name="cover" type="hidden" multiple="true" value="{$ware.cover}">
                        </td>
                    </tr>
                    <tr>
                        <th>缩略图</th>
                        <td>
                            <button id="thumb"></button>
                            <div id="thumbBox"></div>
                        </td>
                    </tr>

                    <tr>
                        <th>商品详情：</th>
                        <td><textarea name="trip" class="common-textarea" id="kindeditor_id" cols="30" style="width: 98%;" rows="10">{$ware.trip}</textarea></td>
                    </tr>

                    <tr>
                        <th><i class="require-red">*</i>商品状态：</th>
                        <td>
                            &nbsp;<input type="radio"  value="1" size="85" name="status" class="common-text" {if ($ware.status eq 1)}checked{/if}>正常&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;<input type="radio" value="0" name="status" size="85" class="commont-text" {if ($ware.status eq 0)}checked{/if}>代审
                        </td>
                    </tr>
                    <input type="hidden" name="id" value="{$ware.id}">

                    <tr>
                        <th></th>
                        <td>
                            <input class="btn btn-primary btn6 mr10" id="andy_line_submit" value="提交" type="button">
                            <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                        </td>
                    </tr>
                    </tbody></table>
            </form>
        </div>
    </div>

</div>
<!--/main-->
<script>
    KindEditor.ready(function(K) {
        window.editor = K.create('#kindeditor_id',{
            uploadJson : '/admin.php/image/kindUpload',
            afterBlur: function(){this.sync();}
        });
    });

    var SCOPE = {
        'save_url' : '/admin.php/ware/add',
        'jump_url' : '/admin.php/ware/lists',
        'ajax_upload_swf' : "__STATIC__/Admin/uploadify/uploadify.swf",
        'ajax_upload_image_url' : '/admin.php/image/ajaxUploadImage',
    }

    $(function(){
        var val = $('#type_id').val();
        if(val == 2){
            $('#wareSeckillPrice').show();
            $("#seckillNum").show();
            $("#startTime").show();
            $("#endTime").show();
        }else if(val == 3) {
            $("#wareCollagePrice").show();
            $("#wareCollagePeople").show();
            $("#wareSeckillPrice").hide();
            $("#seckillNum").hide();
            $("#startTime").hide();
            $("#endTime").hide();
        }
        //判断封面图
        var thumb = "{$ware.cover}";
        if(thumb){
            $('#upload_org_code_img').show();
        }

        //判断缩略图有没有
        var img = "{$ware.img}";
        var url = "{:url('ware/ajaxImage')}";
        if(img){
            $.post(url,{path:img,tpl:'thumb'},function(data){
               $('#thumbBox').append(data);
            });
        }
    });


    //商品分类方法
    function getWareType(obj){
        var value = $(obj).val();
        if(value == 2){
            $('#wareSeckillPrice').show();
            $("#seckillNum").show();
            $("#startTime").show();
            $("#endTime").show();
            $("#wareCollagePrice").hide();
            $("#wareCollagePeople").hide();
            $("#wareCollageTime").hide();
        }else if(value == 3){
            $("#wareCollagePrice").show();
            $("#wareCollagePeople").show();
            $("#wareCollageTime").show();
            $("#wareSeckillPrice").hide();
            $("#seckillNum").hide();
            $("#startTime").hide();
            $("#endTime").hide();
        }else{
            $("#wareCollagePrice").hide();
            $("#wareCollagePeople").hide();
            $("#wareCollageTime").hide();
            $("#wareSeckillPrice").hide();
            $("#seckillNum").hide();
            $("#startTime").hide();
            $("#endTime").hide();
        }

    }

    //商品属性
    function check(obj){
        if($(obj).attr('checked')){
            $(obj).attr('checked',false);
        }else{
            $(obj).attr('checked',true);
        }

    }
</script>
<script>
    //图片上传
    $(function(){
        $('#thumb').uploadify({
            buttonClass : 'bgred',
            buttonText : '上传图片',
            height : 30,
            fileTypeDesc : 'Image Files',
            fileObjName : 'file',
            //允许上传的图片后缀
            fileTypeExts : '*.gif;*.jpg;*.png;*.jpeg',
            swf : "__STATIC__/Admin/uploadify/uploadify.swf",
            uploader : "{:url('ware/ajaxUploadImage',['tpl'=>'thumb'])}",
            width :120,
            onUploadSuccess : function(file,data,response){

                $("#thumbBox").append(data);
            }
        })
    })

    //添加
    $("#andy_line_submit").click(function(){

	   //获取多图
        obj = $('input[name="img"]');
        var img = [];
        for(var i = 0; i < obj.length; i++){
            img.push(obj[i].value);
        }
		
        var config = [];
        $('input[name="config"]:checked').each(function(){ //遍历，将所有选中的值放到数组中
            config.push($(this).val());
        });

        var data = $("#andy_form").serializeArray();
        var postData = {};
        $(data).each(function(){
            postData[this.name] = this.value;
        });
        postData.config = config;
		postData.img = img;

        //获取提交地址
        var url = SCOPE.save_url;
        //获取返回地址
        var jump_url = SCOPE.jump_url;
        $.post(url,postData,function(result){
            if(result.status == 1) {
                //成功
                return dialog.success(result.message,jump_url);
            }else if(result.status == 0) {
                // 失败
                return dialog.error(result.message);
            }
        },'JSON');
    });


</script>
{include file="./public/bottom" /}